
using System;

internal class Memory{
	
	internal short[] mem;
	int memLength;
	NES nes;
	
	internal Memory(NES nes, int byteCount){
		this.nes = nes;
		mem = new short[byteCount];
		memLength = byteCount;
	}
	
	internal void stateLoad(ByteBuffer buf){
		
		if(mem==null)mem=new short[memLength];
		buf.readByteArray(mem);
		
	}
	
	internal void stateSave(ByteBuffer buf){
		
		buf.putByteArray(mem);
		
	}
	
	internal void reset(){
		for(int i=0;i<mem.Length;i++)mem[i] = 0;
	}
	
	internal int getMemSize(){
		return memLength;
	}
	
	internal void write(int address, short value){
		mem[address] = value;
	}
	
	internal short load(int address){
		return mem[address];
	}
	
	internal void dump(string file){
		dump(file,0,mem.Length);
	}
	
	internal void dump(string file, int offset, int length){
		
	
		
	}
	
	internal void write(int address, short[] array, int length){
	
		if(address+length > mem.Length)return;
		System.Array.Copy(array,0,mem,address,length);
		
	}
	
	internal void write(int address, short[] array, int arrayoffset, int length){
		
		if(address+length > mem.Length)return;
		System.Array.Copy(array,arrayoffset,mem,address,length);
		
	}
	
	internal void destroy(){
	
		nes = null;
		mem = null;
		
	}
	
}